# Copyright 2024 The XLS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

package(
    default_applicable_licenses = ["//:license"],
    default_visibility = ["//xls:xls_internal"],
    licenses = ["notice"],  # Apache 2.0
)

cc_library(
    name = "constant_collector",
    srcs = ["constant_collector.cc"],
    hdrs = ["constant_collector.h"],
    deps = [
        ":evaluator",
        ":import_utils",
        ":inference_table",
        ":inference_table_converter",
        ":parametric_struct_instantiator",
        ":populate_table_visitor",
        ":type_annotation_utils",
        ":type_system_tracer",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:constexpr_evaluator",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx:warning_collector",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_cloner",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:ast_utils",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:deduce_utils",
        "//xls/dslx/type_system:parametric_env",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:type_info",
        "//xls/dslx/type_system:type_zero_value",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "function_resolver",
    srcs = ["function_resolver.cc"],
    hdrs = ["function_resolver.h"],
    deps = [
        ":import_utils",
        ":inference_table",
        ":inference_table_converter",
        ":parametric_struct_instantiator",
        ":populate_table_visitor",
        ":trait_deriver",
        ":type_annotation_resolver",
        ":type_annotation_utils",
        ":type_system_tracer",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_cloner",
        "//xls/dslx/frontend:ast_utils",
        "//xls/dslx/frontend:builtin_stubs_utils",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "inference_table",
    srcs = ["inference_table.cc"],
    hdrs = ["inference_table.h"],
    deps = [
        ":type_annotation_utils",
        "//xls/common:casts",
        "//xls/common:visitor",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_cloner",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:parametric_env",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/functional:function_ref",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_library(
    name = "inference_table_converter",
    hdrs = ["inference_table_converter.h"],
    deps = [
        ":inference_table",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "inference_table_converter_impl",
    srcs = ["inference_table_converter_impl.cc"],
    hdrs = ["inference_table_converter_impl.h"],
    deps = [
        ":constant_collector",
        ":evaluator",
        ":fast_concretizer",
        ":flatten_in_type_order",
        ":function_resolver",
        ":import_utils",
        ":inference_table",
        ":inference_table_converter",
        ":parametric_struct_instantiator",
        ":populate_table_visitor",
        ":simplified_type_annotation_cache",
        ":solve_for_parametrics",
        ":trait_deriver",
        ":type_annotation_filter",
        ":type_annotation_resolver",
        ":type_annotation_utils",
        ":type_inference_error_handler",
        ":type_system_tracer",
        ":unify_type_annotations",
        ":validate_concrete_type",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:constexpr_evaluator",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx:warning_collector",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_cloner",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:ast_utils",
        "//xls/dslx/frontend:builtin_stubs_utils",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/frontend:semantics_analysis",
        "//xls/dslx/type_system:parametric_env",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:no_destructor",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/functional:function_ref",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "fast_concretizer_test",
    srcs = ["fast_concretizer_test.cc"],
    deps = [
        ":fast_concretizer",
        ":matchers",
        ":type_annotation_utils",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:type",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "inference_table_test",
    srcs = ["inference_table_test.cc"],
    deps = [
        ":inference_table",
        ":inference_table_converter",
        ":inference_table_converter_impl",
        ":type_annotation_utils",
        ":type_system_test_utils",
        ":type_system_tracer",
        "//xls/common:casts",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/dslx:create_import_data",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx:warning_collector",
        "//xls/dslx:warning_kind",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_cloner",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:parser",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/frontend:scanner",
        "//xls/dslx/type_system:parametric_env",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "solve_for_parametrics",
    srcs = ["solve_for_parametrics.cc"],
    hdrs = ["solve_for_parametrics.h"],
    deps = [
        ":import_utils",
        ":type_annotation_utils",
        "//xls/common:casts",
        "//xls/common/status:status_macros",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:zip_ast",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "trait_deriver",
    hdrs = ["trait_deriver.h"],
    deps = [
        "//xls/dslx/frontend:ast",
        "//xls/dslx/type_system:type",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "trait_deriver_dispatcher",
    hdrs = ["trait_deriver_dispatcher.h"],
    deps = [
        ":trait_deriver",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/type_system:type",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "builtin_trait_deriver",
    srcs = ["builtin_trait_deriver.cc"],
    hdrs = ["builtin_trait_deriver.h"],
    deps = [
        ":trait_deriver",
        ":trait_deriver_dispatcher",
        ":type_annotation_utils",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:errors",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:type",
        "@com_google_absl//absl/functional:function_ref",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "type_inference_error_handler",
    hdrs = ["type_inference_error_handler.h"],
    deps = [
        ":inference_table",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/type_system:type",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "typecheck_module_v2",
    srcs = ["typecheck_module_v2.cc"],
    hdrs = ["typecheck_module_v2.h"],
    deps = [
        ":inference_table",
        ":inference_table_converter",
        ":inference_table_converter_impl",
        ":populate_table",
        ":trait_deriver",
        ":type_inference_error_handler",
        ":type_system_tracer",
        "//xls/common/file:filesystem",
        "//xls/common/status:status_macros",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx:warning_collector",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:semantics_analysis",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:type_info",
        "//xls/tools:typecheck_flags",
        "//xls/tools:typecheck_flags_cc_proto",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "solve_for_parametrics_test",
    srcs = ["solve_for_parametrics_test.cc"],
    deps = [
        ":solve_for_parametrics",
        ":type_annotation_utils",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/dslx:create_import_data",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:parser",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/frontend:scanner",
        "//xls/ir:bits",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "populate_table",
    srcs = ["populate_table.cc"],
    hdrs = ["populate_table.h"],
    deps = [
        ":inference_table",
        ":inference_table_converter",
        ":inference_table_converter_impl",
        ":populate_table_visitor",
        ":type_system_tracer",
        "//xls/common/status:status_macros",
        "//xls/dslx:import_data",
        "//xls/dslx:import_routines",
        "//xls/dslx:warning_collector",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:builtin_stubs_utils",
        "//xls/dslx/frontend:module",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "populate_table_visitor",
    srcs = ["populate_table_visitor.cc"],
    hdrs = ["populate_table_visitor.h"],
    deps = [
        ":import_utils",
        ":inference_table",
        ":type_annotation_utils",
        "//xls/common:casts",
        "//xls/common:visitor",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:channel_direction",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx:import_routines",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:ast_utils",
        "//xls/dslx/frontend:builtins_metadata",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:deduce_utils",
        "//xls/ir:format_strings",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_test(
    name = "typecheck_module_v2_test",
    srcs = ["typecheck_module_v2_test.cc"],
    shard_count = 4,
    deps = [
        ":matchers",
        ":type_system_test_utils",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/dslx:create_import_data",
        "//xls/dslx:import_data",
        "//xls/dslx:virtualizable_file_system",
        "//xls/dslx/type_system:typecheck_test_utils",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "typecheck_module_v2_builtin_test",
    srcs = ["typecheck_module_v2_builtin_test.cc"],
    deps = [
        ":matchers",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/dslx:create_import_data",
        "//xls/dslx:import_data",
        "//xls/dslx/type_system:typecheck_test_utils",
        "@com_google_absl//absl/status:status_matchers",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "typecheck_module_v2_generics_test",
    srcs = ["typecheck_module_v2_generics_test.cc"],
    deps = [
        ":matchers",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/dslx:create_import_data",
        "//xls/dslx:import_data",
        "//xls/dslx/type_system:typecheck_test_utils",
        "@com_google_absl//absl/status:status_matchers",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "typecheck_module_v2_stdlib_test",
    srcs = ["typecheck_module_v2_stdlib_test.cc"],
    deps = [
        ":matchers",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/dslx/type_system:typecheck_test_utils",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "typecheck_module_v2_trait_test",
    srcs = ["typecheck_module_v2_trait_test.cc"],
    shard_count = 4,
    deps = [
        ":matchers",
        ":trait_deriver_dispatcher",
        ":type_annotation_utils",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/common/status:status_macros",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:typecheck_test_utils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@googletest//:gtest",
    ],
)

cc_test(
    name = "typecheck_module_v2_error_handler_test",
    srcs = ["typecheck_module_v2_error_handler_test.cc"],
    deps = [
        ":matchers",
        ":type_annotation_utils",
        ":type_inference_error_handler",
        ":type_system_test_utils",
        "//xls/common:xls_gunit_main",
        "//xls/common/status:matchers",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:typecheck_test_utils",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "type_system_test_utils",
    testonly = True,
    srcs = ["type_system_test_utils.cc"],
    hdrs = ["type_system_test_utils.h"],
    deps = [
        "//xls/dslx:parse_and_typecheck",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "import_utils",
    srcs = ["import_utils.cc"],
    hdrs = ["import_utils.h"],
    deps = [
        ":inference_table",
        ":type_annotation_utils",
        "//xls/common:casts",
        "//xls/common/status:status_macros",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:ast_utils",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:pos",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "type_annotation_filter",
    srcs = ["type_annotation_filter.cc"],
    hdrs = ["type_annotation_filter.h"],
    deps = [
        ":inference_table",
        "//xls/common:casts",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_utils",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "type_annotation_utils",
    srcs = ["type_annotation_utils.cc"],
    hdrs = ["type_annotation_utils.h"],
    deps = [
        "//xls/common:casts",
        "//xls/common/status:status_macros",
        "//xls/dslx:errors",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:pos",
        "//xls/ir:bits",
        "//xls/ir:number_parser",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "validate_concrete_type",
    srcs = ["validate_concrete_type.cc"],
    hdrs = ["validate_concrete_type.h"],
    deps = [
        ":inference_table",
        "//xls/common:casts",
        "//xls/common:visitor",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:constexpr_evaluator",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx:warning_collector",
        "//xls/dslx:warning_kind",
        "//xls/dslx/exhaustiveness:match_exhaustiveness_checker",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:ast_utils",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:deduce_utils",
        "//xls/dslx/type_system:parametric_env",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:type_info",
        "//xls/dslx/type_system:typecheck_invocation",
        "//xls/dslx/type_system:unwrap_meta_type",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:variant",
    ],
)

cc_library(
    name = "unify_type_annotations",
    srcs = ["unify_type_annotations.cc"],
    hdrs = ["unify_type_annotations.h"],
    deps = [
        ":evaluator",
        ":import_utils",
        ":inference_table",
        ":parametric_struct_instantiator",
        ":type_annotation_filter",
        ":type_annotation_utils",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:channel_direction",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:deduce_utils",
        "@com_google_absl//absl/functional:function_ref",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "evaluator",
    srcs = ["evaluator.cc"],
    hdrs = ["evaluator.h"],
    deps = [
        ":inference_table",
        ":inference_table_converter",
        ":type_annotation_utils",
        ":type_system_tracer",
        "//xls/common:casts",
        "//xls/common/status:status_macros",
        "//xls/dslx:constexpr_evaluator",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx:warning_collector",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/type_system:type",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "fast_concretizer",
    srcs = ["fast_concretizer.cc"],
    hdrs = ["fast_concretizer.h"],
    deps = [
        ":type_annotation_utils",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:type",
        "//xls/ir:bits",
        "//xls/ir:bits_ops",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "type_system_tracer",
    srcs = ["type_system_tracer.cc"],
    hdrs = ["type_system_tracer.h"],
    deps = [
        ":inference_table",
        ":type_annotation_filter",
        "//xls/common:indent",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:type",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
    ],
)

cc_test(
    name = "type_system_tracer_test",
    srcs = ["type_system_tracer_test.cc"],
    deps = [
        ":type_annotation_utils",
        ":type_system_tracer",
        "//xls/common:xls_gunit_main",
        "//xls/dslx:create_import_data",
        "//xls/dslx:import_data",
        "//xls/dslx:warning_collector",
        "//xls/dslx:warning_kind",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:module",
        "//xls/dslx/frontend:pos",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "parametric_struct_instantiator",
    hdrs = ["parametric_struct_instantiator.h"],
    deps = [
        ":inference_table",
        ":type_annotation_utils",
        "//xls/dslx:interp_value",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:pos",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "type_annotation_resolver",
    srcs = ["type_annotation_resolver.cc"],
    hdrs = ["type_annotation_resolver.h"],
    deps = [
        ":evaluator",
        ":import_utils",
        ":inference_table",
        ":parametric_struct_instantiator",
        ":simplified_type_annotation_cache",
        ":type_annotation_filter",
        ":type_annotation_utils",
        ":type_system_tracer",
        ":unify_type_annotations",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:errors",
        "//xls/dslx:import_data",
        "//xls/dslx:interp_value",
        "//xls/dslx:status_payload_utils",
        "//xls/dslx:warning_collector",
        "//xls/dslx:warning_kind",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_cloner",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "//xls/dslx/frontend:pos",
        "//xls/dslx/type_system:deduce_utils",
        "//xls/dslx/type_system:type_info",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "matchers",
    testonly = True,
    hdrs = ["matchers.h"],
    deps = [
        ":type_system_test_utils",
        "//xls/dslx:parse_and_typecheck",
        "//xls/dslx:status_payload_cc_proto",
        "//xls/dslx:status_payload_utils",
        "//xls/dslx/type_system:typecheck_test_utils",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "flatten_in_type_order",
    srcs = ["flatten_in_type_order.cc"],
    hdrs = ["flatten_in_type_order.h"],
    deps = [
        ":import_utils",
        "//xls/common:casts",
        "//xls/common/status:ret_check",
        "//xls/common/status:status_macros",
        "//xls/dslx:import_data",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "//xls/dslx/frontend:ast_node_visitor_with_default",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "simplified_type_annotation_cache",
    srcs = ["simplified_type_annotation_cache.cc"],
    hdrs = ["simplified_type_annotation_cache.h"],
    deps = [
        ":inference_table",
        ":unify_type_annotations",
        "//xls/dslx/frontend:ast",
        "//xls/dslx/frontend:ast_node",
        "@com_google_absl//absl/container:flat_hash_map",
    ],
)
